class Solution {
public:
    vector<vector<int>> ret;
    void dfs(vector<int>& candidates, int target, vector<int> path, int sum, int pos)
    {
        if(sum >= target)
        {
            if(sum == target) ret.push_back(path);
            return;
        }
        for(int i = pos; i < candidates.size(); i++)
        {
            path.push_back(candidates[i]);
            dfs(candidates, target, path, sum + candidates[i], i);
            path.pop_back();
        }
    }
    vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
        dfs(candidates, target, vector<int>(), 0, 0);
        return ret;
    }
};